package xyz.qduwo.servlet.manager;

import xyz.qduwo.dao.UserDao;
import xyz.qduwo.util.JsonUtils;
import xyz.qduwo.util.RespUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/manager/DeleteUser")
public class DeleteUser extends HttpServlet {

    /**
     * 用来删除用户数据
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int userId = Integer.parseInt(req.getParameter("userId"));
        UserDao.delete(userId);
        resp.setContentType("application/x-json;charset=utf-8");
        resp.getWriter().println(RespUtils.success(userId));
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        doGet(req,resp);
    }
}
